// UVTimeData.cpp: implementation of the CUVTimeData class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "UVTimeData.h"
#include "../Util/MinUtilExt.h"
#include "../Util/MyProgressWnd.h"
#include "../IO/IIO.h"
#include "../IO/Io_def.h"
#include <mmsystem.h>

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CUVTimeData::CUVTimeData(CString strFileName) : CFileManager(strFileName)
{
	m_sTime = 0;
//	m_Start = FALSE;
}
CUVTimeData::CUVTimeData(CString strFileName, CString strPath) : CFileManager(strFileName, strPath)
{
	m_sTime = 0;
}

CUVTimeData::~CUVTimeData()
{

}
DWORD CUVTimeData::GetTotTime()
{
	//	DWORD t;
	if (m_Start == TRUE)
		return (timeGetTime()-m_sTime+m_TotalTime);
	else
		return (m_TotalTime);	
}
void CUVTimeData::CheckStart()
{
//	m_sTime = 0;
	m_sTime = timeGetTime();
	m_Start = TRUE;
}
void CUVTimeData::CheckStop()
{
	m_TotalTime += (timeGetTime()-m_sTime);
	m_Start = FALSE;
}
int	CUVTimeData::GetHour()
{
	int H = (int)(GetTotTime() / HOUR2MSEC);
	return H;
}
int	CUVTimeData::GetMin()
{
	int M = GetTotTime() % HOUR2MSEC;
	M /= MIN2MSEC;
	return M;
}
int	CUVTimeData::GetSec()
{
	int S = GetTotTime() % HOUR2MSEC;
	S %= MIN2MSEC;
	S /= SEC2MSEC;
	return S;
}
int	CUVTimeData::GetMSec()
{
	int MS = GetTotTime() % SEC2MSEC;
	return MS;
}
int CUVTimeData::Init()
{
	int ret;
	m_TotalTime = 0;
	m_sTime = 0;
	m_Start = FALSE;
	
	m_Hour = 0;
	m_Min = 0;
	m_Sec = 0;
	
	if(!SetValue("UV Total Time", "UV Time Hour", m_Hour))ret = FALSE; 
	if(!SetValue("UV Total Time", "UV Time Min", m_Min))ret = FALSE;
	if(!SetValue("UV Total Time", "UV Time Sec", m_Sec))ret = FALSE;
	
	return TRUE;
}

int CUVTimeData::UVTimeDataLoad()
{

	int ret;
	if(!GetValue("UV Total Time", "UV Time Hour", &m_Hour)) ret = FALSE;
	if(!GetValue("UV Total Time", "UV Time Min", &m_Min)) ret = FALSE;
	if(!GetValue("UV Total Time", "UV Time Sec", &m_Sec)) ret = FALSE;

	m_TotalTime = (m_Hour*60*60 + m_Min*60 + m_Sec)*1000;
	return ret;
}

int CUVTimeData::UVTimeDataSave()
{
	int ret;
	
	m_Hour = GetHour();
	m_Min = GetMin();
	m_Sec = GetSec();

	if(!SetValue("UV Total Time", "UV Time Hour", m_Hour)) ret = FALSE;
	if(!SetValue("UV Total Time", "UV Time Min", m_Min)) ret = FALSE;
	if(!SetValue("UV Total Time", "UV Time Sec", m_Sec)) ret = FALSE;

	return ret;
	
}
